<?php
/**
 * @title 136. 只出现一次的数字 - 异或迭代
 * @author start2004
 */

// ini_set("memory_limit", "128M");

class Solution {

    /**
     * @param Integer[] $nums
     * @return Integer
     */
    function singleNumber($nums) {


        /**
         * @since 2020-08-11 异或迭代
         */
        $n = $nums[0];
        for($i=1, $len=count($nums); $i<$len; $i++){
            $n = $n^$nums[$i];
        }

        /**
         * @return
         */
        return $n;
    }
}



/**
 * @url http://127.0.0.1/leetcode/202008/2020.08.11_5.php
 */
$datas = [
    [2,2,1],
    [4,1,2,1,2],
];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    var_dump($data);

    $obj = new Solution();
    $result = $obj->singleNumber($data);
    var_dump($result);
    echo str_repeat("<br>", 3);
}
$xhprof->end();
